package offer;
//反转链表
public class T15 {

    public class ListNode {
        int val;
        ListNode next = null;

        ListNode(int val) {
            this.val = val;
        }
    }

    public ListNode ReverseList(ListNode head) {
        if (head==null) return null;
         ListNode end = head.next;
         head.next=null;
         while (end!=null) {
             ListNode t = end;
             end = end.next;
             t.next=head;
             head = t;
         }
         return head;
    }

}
